package tcp;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws Exception{
        //创建Socket对象，指定ip和端口
        Socket socket = new Socket("127.0.0.1",7890);
        //获取传输数据的流对象
        InputStream is = socket.getInputStream();
        OutputStream os = socket.getOutputStream();
        //传输数据
        os.write("你是谁".getBytes());

        byte[] bytes = new byte[1024];
        int len = is.read(bytes);
        String msg = new String(bytes,0,len);
        System.out.println(msg);

        //释放资源
        socket.close();
    }
}
